10. Let's Get Ready to Move
Let's Get Ready to Move
Please Note the Following
- After reviewing the course, we have decided it is easier to simply replace the code in the original GameLogic.cs with a copy/paste instead of downloading a new file. Please replace the code in your existing GameLogic.cs script with the updated code provided below.
GoogleVR Related Changes affecting Course Assets and Starter Project
- The
GvrViewerMainprefab you see in the Hierarchy during the videos no longer exist in GoogleVR Unity SDK and is now represented by theGvrEditorEmulatorprefab. - The
Main Camerayou see in the Hierarchy during the videos will typically be nested as a child of theGvrEditorEmulatorprefab. - The
GvrReticleprefab you see in the Hierarchy during the videos has been renamedGvrReticlePointer. - The
GazeInputModulescript no longer exist in GoogleVR Unity SDK and we recommend using theGvrEventSystemprefab instead of the default Unity EventSystem because this prefab already has the required script components. - The stereoscopic view you see in the video while in Game mode is no longer rendered in the Unity Game view due to changes to GoogleVR Unity SDK. However, you can still use
Alt + Move Mouseto simulate head rotation andCtrl + Move Mouseto simulate head tilt. - If you find that
Alt + Move MouseandCtrl + Move Mousedoes not respond once you have entered Game mode, it's most likely because the Unity project is using GoogleVR Unity SDK version 1.6. For this versions of GoogleVR Unity SDK the head rotation and tilt simulation does not work while using Unity desktop platform mode. Therefore, you need to use a mobile platform, by going toFile > Build Settings...and switching to either iOS or Android platform in the Build Settings popup window. - In general, the camera should be nested under a parent gameobject, for example, the
GvrEditorEmulatorprefab, and have a local position and rotation of0, 0, 0. To reposition the camera, the parent gameobject should be repositioned and the camera itself should keep its local position and rotation of0, 0, 0.
Updated GameLogic.cs script
using UnityEngine;
using System.Collections;
public class GameLogic : MonoBehaviour
{
public GameObject player;
public GameObject startUI, restartUI;
public GameObject startPoint, playPoint, restartPoint;
void Start()
{
// Update 'player' to be the camera's parent gameobject, i.e. GvrEditorEmulator, instead of the camera itself.
// Required because GVR resets camera position to 0, 0, 0.
player = player.transform.parent.gameObject;
// Move player to the start position.
player.transform.position = startPoint.transform.position;
}
void Update()
{
if (Input.GetMouseButtonDown(0) && player.transform.position == playPoint.transform.position)
{
PuzzleSuccess();
}
}
// Begin the puzzle sequence.
public void StartPuzzle()
{
ToggleUI();
iTween.MoveTo(player,
iTween.Hash(
"position", playPoint.transform.position,
"time", 2,
"easetype", "linear"
)
);
}
// Reset the puzzle sequence.
public void ResetPuzzle()
{
player.transform.position = startPoint.transform.position;
ToggleUI();
}
// Do this when the player solves the puzzle.
public void PuzzleSuccess()
{
iTween.MoveTo(player,
iTween.Hash(
"position", restartPoint.transform.position,
"time", 2,
"easetype", "linear"
)
);
}
public void ToggleUI()
{
startUI.SetActive(!startUI.activeSelf);
restartUI.SetActive(!restartUI.activeSelf);
}
// Placeholder method to prevent compiler errors caused by this method being called from LightUp.cs.
public void PlayerSelection(GameObject sphere)
{
// Will be completed later in the course.
}
}